﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Inmobiliaria.Presenters;
using System.Web.SessionState;
using System.Collections;

/// <summary>
/// Summary description for WebSession
/// </summary>
public class WebSession //: //IStateBag
{
    private HttpSessionState Session
    {
        get { return HttpContext.Current.Session; }
    }

    public void Add(string name, object value)
    {
        Session.Add(name, value);
    }

    public void Clear()
    {
        Session.Clear();
    }

    public void RemoveAllExcept(List<string> keysNoBorrar)
    {
        Hashtable objectsNoBorrar = new Hashtable();
        // Obtenemos los objetos guardados que no se deben borrar
        foreach (var o in keysNoBorrar)
        {
            object objetoGuardado = Session[o];
            if (objetoGuardado != null)
                objectsNoBorrar.Add(o, objetoGuardado);
        }
        // Borramos toda la session
        Session.Clear();

        // Insertamos nuevamente los que no se debian borrar
        foreach (string key in objectsNoBorrar.Keys)
        {
            Session.Add(key, objectsNoBorrar[key]);
        }
    }

    public bool Contains(string name)
    {
        return Session[name] != null;
    }

    #region IStateBug Members

    //object IStateBag.this[StateBagKeys key]
    //{
    //    get
    //    {
    //        return Session[key.ToString()];
    //    }
    //    set
    //    {
    //        Session[key.ToString()] = value;
    //    }
    //}

    #endregion
}